package com.jtny.nytb.equipment.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.jtny.component.core.util.PageUtils;
import com.jtny.component.core.util.QueryWrapperUtils;
import com.jtny.component.entity.LocalHolder;
import com.jtny.component.entity.PageData;
import com.jtny.component.entity.PageParam;
import com.jtny.component.util.Assert;
import com.jtny.component.util.BeanUtils;
import com.jtny.component.util.CurrentUserUtils;
import com.jtny.nytb.equipment.dao.dataparam.DataParamTempDAO;
import com.jtny.nytb.equipment.dao.rule.*;
import com.jtny.nytb.equipment.domain.dataparam.DataParamTempDO;
import com.jtny.nytb.equipment.domain.rule.*;
import com.jtny.nytb.equipment.enums.CodeRuleTypeEnum;
import com.jtny.nytb.equipment.errorcode.CodeLevelErrorCodeEnum;
import com.jtny.nytb.equipment.service.RuleNumberService;
import com.jtny.nytb.equipment.vo.dataparam.DataParamTempVO;
import com.jtny.nytb.equipment.vo.rule.*;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 智慧能源中心 - 伍天宇
 * @package com.jtny.nytb.equipment.biz.impl
 * @fileName RuleNumberBizImpl.java
 * @createTime 2023年09月15日 14:35
 * @Copyright© 2023 jtny
 * 江投能源技术研究院 版权所有
 */
@Service
@AllArgsConstructor
public class RuleNumberServiceImpl implements RuleNumberService {

    private DataParamTempServiceImpl dataParamTempServiceImpl;

    @Autowired
    private DataParamTempDAO dataParamTempDAO;

    @Autowired
    private CodeRuleDAO codeRuleDAO;

    @Autowired
    private CodeLevelDAO codeLevelDAO;

    @Autowired
    private CodeRulePreconditionDAO codeRulePreconditionDAO;

    @Autowired
    private CodeRuleDictDAO codeRuleDictDAO;

    @Autowired
    private MeterCodeRuleDAO meterCodeRuleDAO;

    @Autowired
    private MeterCodeRulePreconditionDAO meterCodeRulePreconditionDAO;

    @Autowired
    private MeterCodeRuleDictDAO meterCodeRuleDictDAO;

    @Autowired
    private MeterCodeLevelDAO meterCodeLevelDAO;
    /**
     * 查询 设备编号级别 分页
     *
     * @param codeLevelQueryVO 代码级查询 VO
     * @return {@link PageData}<{@link CodeLevelPageVO}>
     */
    @Override
    public PageData<CodeLevelPageVO> queryCodeLevelPage(String type, CodeLevelQueryVO codeLevelQueryVO) {
        Assert.notNull(type, CodeLevelErrorCodeEnum.TYPE_IS_NULL);
        Assert.notNull(codeLevelQueryVO, CodeLevelErrorCodeEnum.PARAM_OBJECT_IS_NULL);
        if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
            // 封装查询条件QueryWrapper对象
            QueryWrapper<CodeLevelDO> queryWrapper = QueryWrapperUtils
                    .getQueryWrapper(codeLevelQueryVO);
            queryWrapper.orderByAsc("sort_number");

            // 分页查询统一用户信息信息
            Page<CodeLevelDO> page = Page
                    .of(codeLevelQueryVO.getPageNo(), codeLevelQueryVO.getPageSize());
            PageData<CodeLevelDO> pageData = PageUtils
                    .getPageData(codeLevelDAO.selectPage(page, queryWrapper), codeLevelQueryVO);
            return pageData.transformData(CodeLevelPageVO.class);
        } else {
            // 封装查询条件QueryWrapper对象
            QueryWrapper<MeterCodeLevelDO> queryWrapper = QueryWrapperUtils
                    .getQueryWrapper(codeLevelQueryVO);
            queryWrapper.orderByAsc("sort_number");

            // 分页查询统一用户信息信息
            Page<MeterCodeLevelDO> page = Page
                    .of(codeLevelQueryVO.getPageNo(), codeLevelQueryVO.getPageSize());
            PageData<MeterCodeLevelDO> pageData = PageUtils
                    .getPageData(meterCodeLevelDAO.selectPage(page, queryWrapper), codeLevelQueryVO);
            return pageData.transformData(CodeLevelPageVO.class);
        }
    }

    /**
     * 列表级别
     *
     * @return {@link List}<{@link LevelNumberInfoVO}>
     */
    @Override
    public List<LevelNumberInfoVO> listLevel(String type) {
        if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
            return listGeneralLevel();
        } else {
            return listMeterLevel();
        }
    }

    private List<LevelNumberInfoVO> listGeneralLevel() {
        QueryWrapper<CodeLevelDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort_number");
        List<CodeLevelDO> codeLevelDOList = codeLevelDAO.selectList(queryWrapper);
        return BeanUtils.copyToList(codeLevelDOList, LevelNumberInfoVO.class);
    }

    private List<LevelNumberInfoVO> listMeterLevel() {
        QueryWrapper<MeterCodeLevelDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort_number");
        List<MeterCodeLevelDO> codeLevelDOList = meterCodeLevelDAO.selectList(queryWrapper);
        return BeanUtils.copyToList(codeLevelDOList, LevelNumberInfoVO.class);
    }

    /**
     * 查询 设备编号规则 分页
     *
     * @param levelId   级别标识
     * @param pageParam 页面参数
     * @return {@link PageData}<{@link CodeRulePageVO}>
     */
    @Override
    public PageData<CodeRulePageVO> queryCodeRulePage(String type, Long levelId, PageParam pageParam) {
//        PageData<CodeRulePageVO> page = codeRuleClient.page(type, levelId, pageParam);
        PageData<RuleFormVO> page;
        Assert.notNull(type, "类型不能为空");

        if (CodeRuleTypeEnum.GENERAL.checkType(type)) {
            page = pageGeneral(levelId, pageParam);
        } else {
            page = pageMeter(levelId, pageParam);
        }
        return page.transformData(CodeRulePageVO.class);

    }

    private PageData<RuleFormVO> pageGeneral(Long levelId, PageParam pageParam) {
        // 封装查询条件QueryWrapper对象
        LambdaQueryWrapper<CodeRuleDO> wrapper = new LambdaQueryWrapper<CodeRuleDO>().eq(CodeRuleDO::getLevelId, levelId);

        // 分页查询统一用户信息信息
        Page<CodeRuleDO> page = Page
                .of(pageParam.getPageNo(), pageParam.getPageSize());
        PageData<CodeRuleDO> pageData = PageUtils
                .getPageData(codeRuleDAO.selectPage(page, wrapper), pageParam);
        return pageData.transformData(RuleFormVO.class);
    }

    private PageData<RuleFormVO> pageMeter(Long levelId, PageParam pageParam) {
        // 封装查询条件QueryWrapper对象
        LambdaQueryWrapper<MeterCodeRuleDO> wrapper = new LambdaQueryWrapper<MeterCodeRuleDO>().eq(MeterCodeRuleDO::getLevelId, levelId);

        // 分页查询统一用户信息信息
        Page<MeterCodeRuleDO> page = Page
                .of(pageParam.getPageNo(), pageParam.getPageSize());
        PageData<MeterCodeRuleDO> pageData = PageUtils
                .getPageData(meterCodeRuleDAO.selectPage(page, wrapper), pageParam);
        return pageData.transformData(RuleFormVO.class);
    }


    /**
     * 保存设备编号级别
     *
     * @param ruleNumberFormVO 设备编号级别表单VO
     * @return {@link Boolean}
     */
    @Override
    public Boolean saveCodeLevel(String type, RuleNumberFormVO ruleNumberFormVO) {
        CurrentUserUtils.setCreateDefaultField(ruleNumberFormVO, LocalHolder.getCurrentUser());
        Assert.notNull(ruleNumberFormVO, CodeLevelErrorCodeEnum.PARAM_OBJECT_IS_NULL);
        Assert.isTrue(checkName(type, ruleNumberFormVO.getName(), ruleNumberFormVO.getId()), CodeLevelErrorCodeEnum.NAME_REPEATED);
        if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
            return saveGeneralCodeLevel(ruleNumberFormVO);
        } else {
            return saveMeterCodeLevel(ruleNumberFormVO);
        }

//        return codeLevelClient.save(type, codeLevelRequestDTO);
    }

    private Boolean saveGeneralCodeLevel(RuleNumberFormVO ruleNumberFormVO) {
        CodeLevelDO codeLevelDO = BeanUtils.copyToObject(ruleNumberFormVO, CodeLevelDO.class);
        codeLevelDO.setSortNumber(getNowSortNumber() + 1);
        return SqlHelper.retBool(codeLevelDAO.insert(codeLevelDO));
    }

    private Boolean saveMeterCodeLevel(RuleNumberFormVO ruleNumberFormVO) {
        MeterCodeLevelDO codeLevelDO = BeanUtils.copyToObject(ruleNumberFormVO, MeterCodeLevelDO.class);
        codeLevelDO.setSortNumber(getNowSortNumber() + 1);
        return SqlHelper.retBool(meterCodeLevelDAO.insert(codeLevelDO));
    }

    private Integer getNowSortNumber() {
        CodeLevelDO codeLevelDO = codeLevelDAO.selectOne(new LambdaQueryWrapper<CodeLevelDO>()
                .orderByDesc(CodeLevelDO::getSortNumber)
                .last("limit 1"));
        return codeLevelDO == null ? 0 : codeLevelDO.getSortNumber();
    }

    /**
     * 更新设备编号级别
     *
     * @param ruleNumberFormVO 设备编号级别 VO
     * @return {@link Boolean}
     */
    @Override
    public Boolean updateCodeLevel(String type, RuleNumberFormVO ruleNumberFormVO) {
        CurrentUserUtils.setUpdateDefaultField(ruleNumberFormVO, LocalHolder.getCurrentUser());
        Assert.notNull(type, CodeLevelErrorCodeEnum.TYPE_IS_NULL);
        Assert.notNull(ruleNumberFormVO, CodeLevelErrorCodeEnum.PARAM_OBJECT_IS_NULL);
        Assert.notNull(ruleNumberFormVO.getId(), CodeLevelErrorCodeEnum.ID_IS_NULL);
        Assert.isTrue(checkName(type, ruleNumberFormVO.getName(), ruleNumberFormVO.getId()), CodeLevelErrorCodeEnum.NAME_REPEATED);
        if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
            return updateGeneralCodeLevel(ruleNumberFormVO);
        } else {
            return updateMeterCodeLevel(ruleNumberFormVO);
        }
    }

    private Boolean updateGeneralCodeLevel(RuleNumberFormVO ruleNumberFormVO) {
        CodeLevelDO codeLevelDO = BeanUtils.copyToObject(ruleNumberFormVO, CodeLevelDO.class);
        CodeLevelDO oldData = codeLevelDAO.selectById(ruleNumberFormVO.getId());
        if (ObjectUtil.isNotNull(oldData.getSortNumber()) && !oldData.getSortNumber().equals(codeLevelDO.getSortNumber())) {
            codeLevelDO.setSortNumber(getNowSortNumber() + 1);
        }
        return SqlHelper.retBool(codeLevelDAO.updateById(codeLevelDO));
    }

    private Boolean updateMeterCodeLevel(RuleNumberFormVO ruleNumberFormVO) {
        MeterCodeLevelDO codeLevelDO = BeanUtils.copyToObject(ruleNumberFormVO, MeterCodeLevelDO.class);
        MeterCodeLevelDO oldData = meterCodeLevelDAO.selectById(ruleNumberFormVO.getId());
        if (ObjectUtil.isNotNull(oldData.getSortNumber()) && !oldData.getSortNumber().equals(codeLevelDO.getSortNumber())) {
            codeLevelDO.setSortNumber(getNowSortNumber() + 1);
        }
        return SqlHelper.retBool(meterCodeLevelDAO.updateById(codeLevelDO));
    }
    /**
     * 删除设备编号级别
     *
     * @param id 主键id
     * @return {@link Boolean}
     */
    @Override
    public Boolean deleteCodeLevel(String type, Long id) {
        Assert.notNull(type, CodeLevelErrorCodeEnum.TYPE_IS_NULL);
        Assert.notNull(id, CodeLevelErrorCodeEnum.ID_IS_NULL);
        if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
            return SqlHelper.retBool(codeLevelDAO.deleteById(id));
        } else {
            return SqlHelper.retBool(meterCodeLevelDAO.deleteById(id));
        }
    }



    /**
     * 根据id查询设备编号级别
     *
     * @param id 主键id
     * @return {@link LevelNumberInfoVO}
     */
    @Override
    public LevelNumberInfoVO detailCodeLevel(String type, Long id) {
        Assert.notNull(type, CodeLevelErrorCodeEnum.TYPE_IS_NULL);
        Assert.notNull(id, CodeLevelErrorCodeEnum.ID_IS_NULL);

        if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
            return detailGeneralCodeLevel(id);
        } else {
            return detailMeterCodeLevel(id);
        }
    }

    private LevelNumberInfoVO detailMeterCodeLevel(Long id) {
        MeterCodeLevelDO codeLevelDO = meterCodeLevelDAO.selectById(id);
        return BeanUtils.copyToObject(codeLevelDO, LevelNumberInfoVO.class);
    }

    private LevelNumberInfoVO detailGeneralCodeLevel(Long id) {
        CodeLevelDO codeLevelDO = codeLevelDAO.selectById(id);
        return BeanUtils.copyToObject(codeLevelDO, LevelNumberInfoVO.class);
    }

    /**
     * 设备编号级别上下移动
     *
     * @param upOrDown 向上或向下
     * @param id       主键id
     * @return {@link Boolean}
     */
    @Override
    public Boolean moveCodeLevel(String type, Integer upOrDown, Long id) {
        Assert.notNull(type, CodeLevelErrorCodeEnum.TYPE_IS_NULL);
        Assert.notNull(upOrDown, CodeLevelErrorCodeEnum.UP_OR_DOWN_IS_NULL);
        Assert.notNull(id, CodeLevelErrorCodeEnum.ID_IS_NULL);
        if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
            return moveGeneralCodeLevel(upOrDown, id);
        } else {
            return moveMeterCodeLevel(upOrDown, id);
        }
    }

    private Boolean moveGeneralCodeLevel(Integer upOrDown, Long id) {
        CodeLevelDO codeLevelDO = codeLevelDAO.selectById(id);
        Long lastOrNextId = getLastOrNext(id, upOrDown);
        if (lastOrNextId == null) {
            return Boolean.TRUE;
        }
        CodeLevelDO lastOrNext = codeLevelDAO.selectById(lastOrNextId);
        if (upOrDown > 0) {
            Integer temp = codeLevelDO.getSortNumber();
            codeLevelDO.setSortNumber(lastOrNext.getSortNumber());
            lastOrNext.setSortNumber(temp);
        } else {
            Integer temp = codeLevelDO.getSortNumber();
            codeLevelDO.setSortNumber(lastOrNext.getSortNumber());
            lastOrNext.setSortNumber(temp);
        }
        codeLevelDAO.updateById(codeLevelDO);
        codeLevelDAO.updateById(lastOrNext);
        return Boolean.TRUE;
    }

    private Boolean moveMeterCodeLevel(Integer upOrDown, Long id) {
        MeterCodeLevelDO codeLevelDO = meterCodeLevelDAO.selectById(id);
        Long lastOrNextId = getLastOrNext(id, upOrDown);
        if (lastOrNextId == null) {
            return Boolean.TRUE;
        }
        MeterCodeLevelDO lastOrNext = meterCodeLevelDAO.selectById(lastOrNextId);
        if (upOrDown > 0) {
            Integer temp = codeLevelDO.getSortNumber();
            codeLevelDO.setSortNumber(lastOrNext.getSortNumber());
            lastOrNext.setSortNumber(temp);
        } else {
            Integer temp = codeLevelDO.getSortNumber();
            codeLevelDO.setSortNumber(lastOrNext.getSortNumber());
            lastOrNext.setSortNumber(temp);
        }
        meterCodeLevelDAO.updateById(codeLevelDO);
        meterCodeLevelDAO.updateById(lastOrNext);
        return Boolean.TRUE;
    }

    /**
     * 保存设备编号规则
     *
     * @param ruleFormVO 设备规则表单VO
     * @return {@link Boolean}
     */
    @Override
    public Boolean saveCodeRule(String type, RuleFormVO ruleFormVO) {
//        CodeRuleRequestDTO codeRuleRequestDTO = ruleFormVO.buildCodeRuleRequestDTO();
        List<CodeRuleDictVO> codeRuleDictList = ruleFormVO.getCodeRuleDictList();
        if (CollUtil.isNotEmpty(codeRuleDictList)) {
            List<CodeRuleDictVO> collect = codeRuleDictList.stream().peek(dto -> dto.setId(null)).collect(Collectors.toList());
            ruleFormVO.setCodeRuleDictList(collect);
        }
        Assert.notNull(type, "类型不能为空");

        if (CodeRuleTypeEnum.GENERAL.checkType(type)) {
            return saveGeneralCodeRule(ruleFormVO);
        } else {
            return saveMeterCodeRule(ruleFormVO);
        }
    }

    private Boolean saveGeneralCodeRule(RuleFormVO ruleFormVO) {
        CodeRuleDO toSave = BeanUtils.copyToObject(ruleFormVO, CodeRuleDO.class);
        boolean result = SqlHelper.retBool(codeRuleDAO.insert(toSave));
        if (result) {
            Long ruleId = toSave.getId();
            // 保存设备编号规则前置条件
            saveCodeRulePreconditionList(ruleFormVO.getCodeRulePreconditionList(), ruleId, ruleFormVO.getLevelId());
            // 保存设备编号规则字典
            saveCodeRuleDictList(ruleFormVO.getCodeRuleDictList(), ruleId);
            // 保存设备编号规则数据参量
            saveDataParamTempList(ruleFormVO.getDataParamTempList(), ruleId, 1);
        }
        return result;
    }

    private Boolean saveMeterCodeRule(RuleFormVO ruleFormVO) {
        MeterCodeRuleDO toSave = BeanUtils.copyToObject(ruleFormVO, MeterCodeRuleDO.class);
        boolean result = SqlHelper.retBool(meterCodeRuleDAO.insert(toSave));
        if (result) {
            Long ruleId = toSave.getId();
            // 保存设备编号规则前置条件
            saveMeterCodeRulePreconditionList(ruleFormVO.getCodeRulePreconditionList(), ruleId, ruleFormVO.getLevelId());
            // 保存设备编号规则字典
            saveMeterCodeRuleDictList(ruleFormVO.getCodeRuleDictList(), ruleId);
            // 保存设备编号规则数据参量
            saveDataParamTempList(ruleFormVO.getDataParamTempList(), ruleId, 3);
        }
        return result;
    }

    /**
     * 更新设备编号规则
     *
     * @param ruleFormVO 设备规则表单VO
     * @return {@link Boolean}
     */
    @Override
    public Boolean updateCodeRule(String type, RuleFormVO ruleFormVO) {
//        CodeRuleRequestDTO codeRuleRequestDTO = ruleFormVO.buildCodeRuleRequestDTO();
        Assert.notNull(type, "类型不能为空");

        if (CodeRuleTypeEnum.GENERAL.checkType(type)) {
            return updateGeneralCodeRule(ruleFormVO);
        } else {
            return updateMeterCodeRule(ruleFormVO);
        }
//        return codeRuleClient.update(type, codeRuleRequestDTO);
    }

    private Boolean updateMeterCodeRule(RuleFormVO ruleFormVO) {
        // 更新设备编号规则
        MeterCodeRuleDO toUpdate = BeanUtils.copyToObject(ruleFormVO, MeterCodeRuleDO.class);
        boolean result = SqlHelper.retBool(meterCodeRuleDAO.updateById(toUpdate));
        if (result) {
            Long ruleId = toUpdate.getId();
            // 保存设备编号规则前置条件
            saveMeterCodeRulePreconditionList(ruleFormVO.getCodeRulePreconditionList(), ruleId, ruleFormVO.getLevelId());
            // 保存设备编号规则字典
            saveMeterCodeRuleDictList(ruleFormVO.getCodeRuleDictList(), ruleId);
            // 保存设备编号规则数据参量
            saveDataParamTempList(ruleFormVO.getDataParamTempList(), ruleId, 3);
        }
        return result;
    }

    private Boolean updateGeneralCodeRule(RuleFormVO ruleFormVO) {
        // 更新设备编号规则
        CodeRuleDO toUpdate = BeanUtils.copyToObject(ruleFormVO, CodeRuleDO.class);
        boolean result = SqlHelper.retBool(codeRuleDAO.updateById(toUpdate));
        if (result) {
            Long ruleId = toUpdate.getId();
            // 保存设备编号规则前置条件
            saveCodeRulePreconditionList(ruleFormVO.getCodeRulePreconditionList(), ruleId, ruleFormVO.getLevelId());
            // 保存设备编号规则字典
            saveCodeRuleDictList(ruleFormVO.getCodeRuleDictList(), ruleId);
            // 保存设备编号规则数据参量
            saveDataParamTempList(ruleFormVO.getDataParamTempList(), ruleId, 1);
        }
        return result;
    }

    /**
     * 详细设备编号规则
     *
     * @param id 主键id
     * @return {@link RuleInfoVO}
     */
    @Override
    public RuleInfoVO detailCodeRule(String type, Long id) {
//        CodeRuleResponseDTO codeRuleResponseDTO = codeRuleClient.getById(type, id);
        Assert.notNull(type, "类型不能为空");
        RuleFormVO ruleFormVO;

        if (CodeRuleTypeEnum.GENERAL.checkType(type)) {
            ruleFormVO = getByIdGeneralCodeRule(id);
        } else {
            ruleFormVO = getByIdMeterCodeRule(id);
        }
        RuleInfoVO result = BeanUtils.copyToObject(ruleFormVO, RuleInfoVO.class);
        // 全量返回参量list信息
        buildDataParamTempList(result);
        return result;
    }

    private RuleFormVO getByIdMeterCodeRule(Long id) {
        // 根据id查询 设备编号规则
        MeterCodeRuleDO codeRuleDO = meterCodeRuleDAO.selectById(id);
        // 根据规则id查询 设备编号规则数据参量
        List<DataParamTempDO> dataParamTempDOList = dataParamTempDAO.selectList(Wrappers.<DataParamTempDO>lambdaQuery()
                .eq(DataParamTempDO::getRelationType, 1)
                .eq(DataParamTempDO::getRelationId, id));
        // 根据规则id查询 设备编号规则前置条件
        List<MeterCodeRulePreconditionDO> codeRulePreconditionDOList = meterCodeRulePreconditionDAO.selectList(Wrappers.<MeterCodeRulePreconditionDO>lambdaQuery()
                .eq(MeterCodeRulePreconditionDO::getRuleId, id));
        // 根据规则id查询 设备编号规则字典
        List<MeterCodeRuleDictDO> codeRuleDictDOList = meterCodeRuleDictDAO.selectList(Wrappers.<MeterCodeRuleDictDO>lambdaQuery()
                .eq(MeterCodeRuleDictDO::getRuleId, id));

        return buildCodeRuleResponseDTO(codeRuleDO, codeRulePreconditionDOList, codeRuleDictDOList, dataParamTempDOList);
    }

    private RuleFormVO getByIdGeneralCodeRule(Long id) {
        // 根据id查询 设备编号规则
        CodeRuleDO codeRuleDO = codeRuleDAO.selectById(id);
        // 根据规则id查询 设备编号规则数据参量
        List<CodeRulePreconditionDO> codeRulePreconditionDOList = codeRulePreconditionDAO.selectList(Wrappers.<CodeRulePreconditionDO>lambdaQuery()
                .eq(CodeRulePreconditionDO::getRuleId, id));
        // 根据规则id查询 设备编号规则字典
        List<CodeRuleDictDO> codeRuleDictDOList = codeRuleDictDAO.selectList(Wrappers.<CodeRuleDictDO>lambdaQuery()
                .eq(CodeRuleDictDO::getRuleId, id));
        // 根据规则id查询 设备编号规则数据参量
        List<DataParamTempDO> dataParamTempDOList = dataParamTempDAO.selectList(Wrappers.<DataParamTempDO>lambdaQuery()
                .eq(DataParamTempDO::getRelationType, 1)
                .eq(DataParamTempDO::getRelationId, id));

        return buildCodeRuleResponseDTO(codeRuleDO, codeRulePreconditionDOList, codeRuleDictDOList, dataParamTempDOList);
    }




    private void buildDataParamTempList(RuleInfoVO result) {
        List<DataParamTempVO> dataParamTempList = result.getDataParamTempList();
        if (CollUtil.isEmpty(dataParamTempList)) {
            return;
        }
        List<DataParamTempVO> collect = dataParamTempList.stream().map(vo -> {
            return dataParamTempServiceImpl.getById(vo.getId());
        }).collect(Collectors.toList());
        result.setDataParamTempList(collect);
    }

    /**
     * 删除设备编号规则
     *
     * @param id 主键id
     * @return {@link Boolean}
     */
    @Override
    public Boolean deleteCodeRule(String type, Long id) {
//        return codeRuleClient.delete(type, id);
        Assert.notNull(type, "类型不能为空");

        if (CodeRuleTypeEnum.GENERAL.checkType(type)) {
            return deleteGeneralCodeRule(id);
        } else {
            return deleteMeterCodeRule(id);
        }
    }

    private Boolean deleteGeneralCodeRule(Long id) {
        // 删除设备编号规则
        codeRuleDAO.deleteById(id);
        // 删除设备编号规则前置条件
        saveCodeRulePreconditionList(null, id, null);
        // 删除设备编号规则字典
        saveCodeRuleDictList(null, id);
        // 删除设备编号规则数据参量
        saveDataParamTempList(null, id, null);
        return Boolean.TRUE;
    }

    private Boolean deleteMeterCodeRule(Long id) {
        // 删除设备编号规则
        meterCodeRuleDAO.deleteById(id);
        // 删除设备编号规则前置条件
        saveMeterCodeRulePreconditionList(null, id, null);
        // 删除设备编号规则字典
        saveMeterCodeRuleDictList(null, id);
        // 删除设备编号规则数据参量
        saveDataParamTempList(null, id, null);
        return Boolean.TRUE;
    }



    /**
     * 列表规则编号
     *
     * @param levelId               级别标识
     * @param codeRuleDictQueryList 查询条件
     * @return {@link List}<{@link CodeRuleDictVO}>
     */
    @Override
    public List<CodeRuleDictVO> listRuleDictSelect(String type, Long levelId, List<CodeRuleDictQueryVO> codeRuleDictQueryList) {
        CodeRuleDictSelectQueryVO codeRuleDictSelectQueryVO = new CodeRuleDictSelectQueryVO();
        codeRuleDictSelectQueryVO.setTargetLevelId(levelId);
        codeRuleDictSelectQueryVO.setCodeRuleDictQueryList(BeanUtils.copyToList(codeRuleDictQueryList, CodeRuleDictQueryVO.class));
        Assert.notNull(type, "类型不能为空");
        if (CodeRuleTypeEnum.GENERAL.checkType(type)) {
            return listRuleDictSelectGeneral(codeRuleDictSelectQueryVO);
        } else {
            return listRuleDictSelectMeter(codeRuleDictSelectQueryVO);
        }
    }




    /**
     * 获取所有规则编号字典项
     *
     * @param levelId 级别标识
     * @return {@link List}<{@link CodeRuleDictVO}>
     */
    @Override
    public List<CodeRuleDictVO> listAllDictByRuleLevel(String type, Long levelId) {
        CodeRuleDictSelectQueryVO codeRuleDictSelectQueryVO = new CodeRuleDictSelectQueryVO();
        codeRuleDictSelectQueryVO.setTargetLevelId(levelId);
        Assert.notNull(type, "类型不能为空");
        if (CodeRuleTypeEnum.GENERAL.checkType(type)) {
            return listRuleDictSelectGeneral(codeRuleDictSelectQueryVO);
        } else {
            return listRuleDictSelectMeter(codeRuleDictSelectQueryVO);
        }
    }

    private List<CodeRuleDictVO> listRuleDictSelectMeter(CodeRuleDictSelectQueryVO codeRuleDictSelectQueryVO) {
        Long targetLevelId = codeRuleDictSelectQueryVO.getTargetLevelId();
        List<CodeRuleDictQueryVO> codeRuleDictQueryList = codeRuleDictSelectQueryVO.getCodeRuleDictQueryList();
        List<Long> ruleIdList = new ArrayList<>();

        // 目标级别ID为空，直接返回空列表
        if (codeRuleDictQueryList == null) {
            ruleIdList = meterCodeRulePreconditionDAO.listRuleIdByTargetLevelId(targetLevelId);
        } else if (codeRuleDictQueryList.isEmpty()) {
            ruleIdList = meterCodeRulePreconditionDAO.listRuleIdByTargetLevelIdAndDictIds(targetLevelId);
        } else {
            // 根据目标级别ID和字典查询列表查询规则ID列表
            for (CodeRuleDictQueryVO codeRuleDictQuery : codeRuleDictQueryList) {
                List<Long> temp = meterCodeRulePreconditionDAO.listRuleIdByTargetLevelIdAndDictQuery(targetLevelId, codeRuleDictQuery);
                if (CollUtil.isEmpty(ruleIdList)) {
                    ruleIdList = temp;
                } else {
                    ruleIdList.retainAll(temp);
                }
            }
        }

        // 清洗处理的规则ID列表
        List<Long> cleanRuleIdList = ruleIdList.stream().distinct().collect(Collectors.toList());
        if (CollUtil.isEmpty(cleanRuleIdList)) {
            return CollUtil.newArrayList();
        }

        List<MeterCodeRuleDictDO> codeRuleDictList = meterCodeRuleDictDAO.selectList(new LambdaQueryWrapper<MeterCodeRuleDictDO>()
                .in(MeterCodeRuleDictDO::getRuleId, cleanRuleIdList)
                .orderByAsc(MeterCodeRuleDictDO::getSortNumber));
        return BeanUtils.copyToList(codeRuleDictList, CodeRuleDictVO.class);
    }

    private List<CodeRuleDictVO> listRuleDictSelectGeneral(CodeRuleDictSelectQueryVO codeRuleDictSelectQueryDTO) {
        Long targetLevelId = codeRuleDictSelectQueryDTO.getTargetLevelId();
        List<CodeRuleDictQueryVO> codeRuleDictQueryList = codeRuleDictSelectQueryDTO.getCodeRuleDictQueryList();
        List<Long> ruleIdList = new ArrayList<>();

        // 目标级别ID为空，直接返回空列表
        if (codeRuleDictQueryList == null) {
            ruleIdList = codeRulePreconditionDAO.listRuleIdByTargetLevelId(targetLevelId);
        } else if (codeRuleDictQueryList.isEmpty()) {
            ruleIdList = codeRulePreconditionDAO.listRuleIdByTargetLevelIdAndDictIds(targetLevelId);
        } else {
            // 根据目标级别ID和字典查询列表查询规则ID列表
            for (CodeRuleDictQueryVO codeRuleDictQuery : codeRuleDictQueryList) {
                List<Long> temp = codeRulePreconditionDAO.listRuleIdByTargetLevelIdAndDictQuery(targetLevelId, codeRuleDictQuery);
                if (CollUtil.isEmpty(ruleIdList)) {
                    ruleIdList = temp;
                } else {
                    ruleIdList.retainAll(temp);
                }
            }
        }

        // 清洗处理的规则ID列表
        List<Long> cleanRuleIdList = ruleIdList.stream().distinct().collect(Collectors.toList());
        if (CollUtil.isEmpty(cleanRuleIdList)) {
            return CollUtil.newArrayList();
        }

        List<CodeRuleDictDO> codeRuleDictList = codeRuleDictDAO.selectList(new LambdaQueryWrapper<CodeRuleDictDO>()
                .in(CodeRuleDictDO::getRuleId, cleanRuleIdList)
                .orderByAsc(CodeRuleDictDO::getSortNumber));
        return BeanUtils.copyToList(codeRuleDictList, CodeRuleDictVO.class);
    }


    /**
     * 按级别 ID 列出级别
     *
     * @param nowLevelId 现在级别 ID
     * @return {@link List}<{@link LevelNumberInfoVO}>
     */
    @Override
    public List<LevelNumberInfoVO> listLevelByLevelId(String type, Long nowLevelId) {
        List<LevelNumberInfoVO> result = listLevel(type);
        List<LevelNumberInfoVO> levelNumberInfoVOList = new ArrayList<>();

        if (CollUtil.isEmpty(result)) {
            return levelNumberInfoVOList;
        }
        // 按顺序排序了的，循环过滤掉当前级别及以下
        for (LevelNumberInfoVO levelNumberInfoVO : result) {
            if (levelNumberInfoVO.getId().equals(nowLevelId)) {
                return levelNumberInfoVOList;
            }
            levelNumberInfoVOList.add(BeanUtils.copyToObject(levelNumberInfoVO, LevelNumberInfoVO.class));
        }
        return levelNumberInfoVOList;
    }

    /**
     * 检查字典值
     *
     * @param type        类型
     * @param validDictVO 有效字典 VO
     * @return {@link ValidDictVO}
     */
    @Override
    public ValidDictVO checkDictValue(String type, ValidDictVO validDictVO) {
        List<CodeRuleDictVO> codeRuleDictList = listRuleDictSelect(type, validDictVO.getLevelId(), null);
        ValidDictVO now = null;
        if (CollUtil.isEmpty(codeRuleDictList)) {
            now = validDictVO;
        }
        for (CodeRuleDictVO codeRuleDictVO : codeRuleDictList) {
            if (StrUtil.equals(codeRuleDictVO.getValue(), validDictVO.getValue())) {
                validDictVO.setDescription(codeRuleDictVO.getDescription());
                now = validDictVO;
            }
        }
        return now;
    }

    /**
     * 获取上一个或下一个
     *
     * @param id       主键ID
     * @param upOrDown 上移或下移
     * @return {@link Long}
     */
    private Long getLastOrNext(Long id, Integer upOrDown) {
        QueryWrapper<CodeLevelDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort_number");
        List<CodeLevelDO> codeLevelDOList = codeLevelDAO.selectList(queryWrapper);
        if (codeLevelDOList.isEmpty()) {
            return null;
        }
        for (int i = 0; i < codeLevelDOList.size(); i++) {
            if (codeLevelDOList.get(i).getId().equals(id)) {
                if (upOrDown > 0) {
                    if (i == 0) {
                        return null;
                    }
                    return codeLevelDOList.get(i - 1).getId();
                } else {
                    if (i == codeLevelDOList.size() - 1) {
                        return null;
                    }
                    return codeLevelDOList.get(i + 1).getId();
                }
            }
        }
        return null;
    }

    /**
     * 校验名称是否重复
     *
     * @param type 类型
     * @param name 名称
     * @param id   主键ID
     * @return {@link Boolean}
     */
    private Boolean checkName(String type, String name, Long id) {
        if (ObjectUtil.isEmpty(id)) {
            if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
                return !codeLevelDAO.exists(Wrappers.<CodeLevelDO>lambdaQuery().eq(CodeLevelDO::getName, name));
            } else {
                return !meterCodeLevelDAO.exists(Wrappers.<MeterCodeLevelDO>lambdaQuery().eq(MeterCodeLevelDO::getName, name));
            }
        } else {
            if (CodeRuleTypeEnum.GENERAL.getType().equals(type)) {
                return !codeLevelDAO.exists(Wrappers.<CodeLevelDO>lambdaQuery().eq(CodeLevelDO::getName, name).ne(CodeLevelDO::getId, id));
            } else {
                return !meterCodeLevelDAO.exists(Wrappers.<MeterCodeLevelDO>lambdaQuery().eq(MeterCodeLevelDO::getName, name).ne(MeterCodeLevelDO::getId, id));
            }
        }
    }

    /**
     * 保存代码规则前提条件列表
     *
     * @param codeRulePreconditionList 代码规则前提条件列表
     * @param ruleId                   规则标识
     */
    private void saveCodeRulePreconditionList(List<CodeRulePreconditionVO> codeRulePreconditionList, Long ruleId, Long levelId) {
        // 清理原有的字典数据
        codeRulePreconditionDAO.delete(Wrappers.<CodeRulePreconditionDO>lambdaQuery().eq(CodeRulePreconditionDO::getRuleId, ruleId));
        // 重新保存
        if (CollectionUtil.isNotEmpty(codeRulePreconditionList)) {
            codeRulePreconditionList.forEach(codeRulePreconditionVO -> {
                CodeRulePreconditionDO codeRulePreconditionDO =
                        BeanUtils.copyToObject(codeRulePreconditionVO, CodeRulePreconditionDO.class);
                codeRulePreconditionDO.setId(null);
                codeRulePreconditionDO.setRuleId(ruleId);
                codeRulePreconditionDO.setTargetLevelId(levelId);
                // 特殊处理 rule_dict_ids 字段 起始末尾加上逗号 方便查询使用
                if (StrUtil.isNotBlank(codeRulePreconditionDO.getRuleDictIds())) {
                    codeRulePreconditionDO.setRuleDictIds(StrUtil.C_COMMA + codeRulePreconditionDO.getRuleDictIds() + StrUtil.C_COMMA);
                }
                codeRulePreconditionDAO.insert(codeRulePreconditionDO);
            });
        } else {
            if (levelId != null) {
                // 保存前置规则条件关联关系
                CodeRulePreconditionDO codeRulePreconditionDO = new CodeRulePreconditionDO();
                codeRulePreconditionDO.setId(null);
                codeRulePreconditionDO.setRuleId(ruleId);
                codeRulePreconditionDO.setTargetLevelId(levelId);
                codeRulePreconditionDAO.insert(codeRulePreconditionDO);
            }
        }
    }

    /**
     * 保存代码规则字典列表
     *
     * @param codeRuleDictList 代码规则字典 dtolist
     * @param ruleId           规则标识
     */
    private void saveMeterCodeRuleDictList(List<CodeRuleDictVO> codeRuleDictList, Long ruleId) {
        // 清理原有的字典数据
        meterCodeRuleDictDAO.delete(Wrappers.<MeterCodeRuleDictDO>lambdaQuery().eq(MeterCodeRuleDictDO::getRuleId, ruleId));
        // 重新保存
        if (CollectionUtil.isNotEmpty(codeRuleDictList)) {
            List<MeterCodeRuleDictDO> collect = codeRuleDictList.stream().map(codeRuleDictVO -> {
                MeterCodeRuleDictDO codeRuleDictDO = BeanUtils.copyToObject(codeRuleDictVO, MeterCodeRuleDictDO.class);
                codeRuleDictDO.setId(null);
                codeRuleDictDO.setRuleId(ruleId);
                return codeRuleDictDO;
            }).collect(Collectors.toList());
            meterCodeRuleDictDAO.insertBatch(collect);
        }
    }

    /**
     * 保存代码规则前提条件列表
     *
     * @param codeRulePreconditionList 代码规则前提条件列表
     * @param ruleId                   规则标识
     */
    private void saveMeterCodeRulePreconditionList(List<CodeRulePreconditionVO> codeRulePreconditionList, Long ruleId, Long levelId) {
        // 清理原有的字典数据
        meterCodeRulePreconditionDAO.delete(Wrappers.<MeterCodeRulePreconditionDO>lambdaQuery().eq(MeterCodeRulePreconditionDO::getRuleId, ruleId));
        // 重新保存
        if (CollectionUtil.isNotEmpty(codeRulePreconditionList)) {
            codeRulePreconditionList.forEach(codeRulePreconditionVO -> {
                MeterCodeRulePreconditionDO codeRulePreconditionDO =
                        BeanUtils.copyToObject(codeRulePreconditionVO, MeterCodeRulePreconditionDO.class);
                codeRulePreconditionDO.setId(null);
                codeRulePreconditionDO.setRuleId(ruleId);
                codeRulePreconditionDO.setTargetLevelId(levelId);
                // 特殊处理 rule_dict_ids 字段 起始末尾加上逗号 方便查询使用
                if (StrUtil.isNotBlank(codeRulePreconditionDO.getRuleDictIds())) {
                    codeRulePreconditionDO.setRuleDictIds(StrUtil.C_COMMA + codeRulePreconditionDO.getRuleDictIds() + StrUtil.C_COMMA);
                }
                meterCodeRulePreconditionDAO.insert(codeRulePreconditionDO);
            });
        } else {
            if (levelId != null) {
                // 保存前置规则条件关联关系
                MeterCodeRulePreconditionDO codeRulePreconditionDO = new MeterCodeRulePreconditionDO();
                codeRulePreconditionDO.setId(null);
                codeRulePreconditionDO.setRuleId(ruleId);
                codeRulePreconditionDO.setTargetLevelId(levelId);
                meterCodeRulePreconditionDAO.insert(codeRulePreconditionDO);
            }
        }
    }

    /**
     * 保存代码规则字典列表
     *
     * @param codeRuleDictVOList 代码规则字典 volist
     * @param ruleId              规则标识
     */
    private void saveCodeRuleDictList(List<CodeRuleDictVO> codeRuleDictVOList, Long ruleId) {
        if (CollUtil.isEmpty(codeRuleDictVOList)) {
            codeRuleDictDAO.delete(Wrappers.<CodeRuleDictDO>lambdaQuery().eq(CodeRuleDictDO::getRuleId, ruleId));
            return;
        }
        // 走增量更新 考虑后续字典项关联的东西太多，不直接删除
        List<CodeRuleDictDO> oldCodeRuleDictList = codeRuleDictDAO.selectList(Wrappers.<CodeRuleDictDO>lambdaQuery()
                .eq(CodeRuleDictDO::getRuleId, ruleId));

        // 要新增的数据
        List<CodeRuleDictVO> toSaveList = codeRuleDictVOList.stream()
                .filter(VO -> ObjectUtils.isEmpty(VO.getId()))
                .collect(Collectors.toList());

        toSaveBatch(toSaveList, ruleId);

        // 要更新的数据
        List<CodeRuleDictVO> toUpdateList = codeRuleDictVOList.stream()
                .filter(VO -> ObjectUtils.isNotEmpty(VO.getId()))
                .collect(Collectors.toList());

        toUpdateBatch(toUpdateList, ruleId);

        if (CollUtil.isNotEmpty(oldCodeRuleDictList)) {
            // 要删除的数据
            List<CodeRuleDictDO> toDeleteList = oldCodeRuleDictList.stream()
                    .filter(vo -> toUpdateList.stream().noneMatch(vo1 -> vo1.getId().equals(vo.getId())))
                    .collect(Collectors.toList());
            toDeleteBatch(toDeleteList);
        }

    }

    /**
     * 保存数据参数临时列表
     *
     * @param dataParamTempList 数据参数临时列表
     * @param ruleId            规则标识
     */
    private void saveDataParamTempList(List<DataParamTempVO> dataParamTempList, Long ruleId, Integer type) {
        // 清理原有的数据参量数据
        dataParamTempDAO.delete(Wrappers.<DataParamTempDO>lambdaQuery()
                .eq(DataParamTempDO::getRelationType, type)
                .eq(DataParamTempDO::getRelationId, ruleId));
//        dataParamTempService.saveBatch(dataParamTempList, ruleId, type);
        if (CollUtil.isEmpty(dataParamTempList)) {
            return;
        }
        dataParamTempList.forEach(dataParamTempVO -> {
            dataParamTempVO.setRelationId(ruleId);
            dataParamTempVO.setRelationType(type);

            dataParamTempServiceImpl.save(dataParamTempVO);
        });
    }

    private void toSaveBatch(List<CodeRuleDictVO> toSaveList, Long ruleId) {
        if (CollectionUtil.isNotEmpty(toSaveList)) {
            List<CodeRuleDictDO> collect = toSaveList.stream().map(codeRuleDictDTO -> {
                CodeRuleDictDO codeRuleDictDO = BeanUtils.copyToObject(codeRuleDictDTO, CodeRuleDictDO.class);
                codeRuleDictDO.setId(null);
                codeRuleDictDO.setRuleId(ruleId);
                return codeRuleDictDO;
            }).collect(Collectors.toList());
            codeRuleDictDAO.insertBatch(collect);
        }
    }

    private void toUpdateBatch(List<CodeRuleDictVO> toUpdateList, Long ruleId) {
        if (CollectionUtil.isNotEmpty(toUpdateList)) {
            List<CodeRuleDictDO> collect = toUpdateList.stream().map(codeRuleDictDTO -> {
                CodeRuleDictDO codeRuleDictDO = BeanUtils.copyToObject(codeRuleDictDTO, CodeRuleDictDO.class);
                codeRuleDictDO.setRuleId(ruleId);
                return codeRuleDictDO;
            }).collect(Collectors.toList());
            codeRuleDictDAO.updateBatch(collect);
        }
    }

    private void toDeleteBatch(List<CodeRuleDictDO> toDeleteList) {
        if (CollectionUtil.isNotEmpty(toDeleteList)) {
            List<Long> ids = toDeleteList.stream().map(CodeRuleDictDO::getId).collect(Collectors.toList());
            codeRuleDictDAO.deleteBatchIds(ids);

            ids.forEach(id -> {
                codeRulePreconditionDAO.delete(Wrappers.<CodeRulePreconditionDO>lambdaQuery()
                        .like(CodeRulePreconditionDO::getRuleDictIds, StrUtil.C_COMMA + id + StrUtil.C_COMMA));
            });
        }
    }

    /**
     * 构建 设备编号规则返回DTO对象
     *
     * @param codeRuleDO                 设备编号规则DO对象
     * @param codeRulePreconditionDOList 设备编号规则前置条件DO列表
     * @param codeRuleDictDOList         设备编号规则字典DO列表
     * @param dataParamTempDOList        设备编号规则数据参量DO列表
     * @return {@link RuleFormVO}
     */
    private RuleFormVO buildCodeRuleResponseDTO(CodeRuleDO codeRuleDO,
                                                         List<CodeRulePreconditionDO> codeRulePreconditionDOList,
                                                         List<CodeRuleDictDO> codeRuleDictDOList,
                                                         List<DataParamTempDO> dataParamTempDOList) {
        RuleFormVO codeRuleResponseDTO = new RuleFormVO();
        // 设备编号规则DO对象转换为VO对象
        BeanUtils.copyObject(codeRuleDO, codeRuleResponseDTO);
        // 设备编号规则前置条件DO列表转换为VO列表
        List<CodeRulePreconditionVO> codeRulePreconditionList = BeanUtils
                .copyToList(codeRulePreconditionDOList, CodeRulePreconditionVO.class);
        codeRuleResponseDTO.setCodeRulePreconditionList(codeRulePreconditionList);
        // 设备编号规则字典DO列表转换为VO列表
        codeRuleResponseDTO.setCodeRuleDictList(BeanUtils.copyToList(codeRuleDictDOList, CodeRuleDictVO.class));
        // 设备编号规则数据参量DO列表转换为VO列表
        codeRuleResponseDTO.setDataParamTempList(BeanUtils.copyToList(dataParamTempDOList, DataParamTempVO.class));
        return codeRuleResponseDTO;
    }

    private RuleFormVO buildCodeRuleResponseDTO(MeterCodeRuleDO codeRuleDO,
                                                         List<MeterCodeRulePreconditionDO> codeRulePreconditionDOList,
                                                         List<MeterCodeRuleDictDO> codeRuleDictDOList,
                                                         List<DataParamTempDO> dataParamTempDOList) {
        RuleFormVO ruleFormVO = new RuleFormVO();
        // 设备编号规则DO对象转换为VO对象
        BeanUtils.copyObject(codeRuleDO, ruleFormVO);
        // 设备编号规则前置条件DO列表转换为VO列表
        List<CodeRulePreconditionVO> codeRulePreconditionList = BeanUtils
                .copyToList(codeRulePreconditionDOList, CodeRulePreconditionVO.class);
        ruleFormVO.setCodeRulePreconditionList(codeRulePreconditionList);
        // 设备编号规则字典DO列表转换为VO列表
        ruleFormVO.setCodeRuleDictList(BeanUtils.copyToList(codeRuleDictDOList, CodeRuleDictVO.class));
        // 设备编号规则数据参量DO列表转换为VO列表
        ruleFormVO.setDataParamTempList(BeanUtils.copyToList(dataParamTempDOList, DataParamTempVO.class));
        return ruleFormVO;
    }
}
